package co.fitstart.market.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.annotation.Dynamic;

import co.fitstart.entity.market.InvitationStatus;
import co.fitstart.entity.market.MarketInvitationRecord;
import co.fitstart.market.dao.MarketInvitationRecordDao;
import co.fitstart.market.service.MarketInvitationRecordService;

/**
 * 
 * @author dan
 *
 */
@Service("marketInvitationRecordService")
public class MarketInvitationRecordServiceImpl implements MarketInvitationRecordService{

    @Dynamic
    private MarketInvitationRecordDao marketInvitationRecordDao;
    
    @Autowired
    private GenericDaoSupport genericDaoSupport;
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.market.service.MarketInvitationRecordService#list(java.lang.String)
     */
    public List<MarketInvitationRecord> list(String inviter) {
        return marketInvitationRecordDao.list(inviter, InvitationStatus.SIGN_UP);
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.market.service.MarketInvitationRecordService#create(java.lang.String, java.lang.String)
     */
    public void create(String inviter, String invitee) {
        // 创建邀请记录
        genericDaoSupport.save(new MarketInvitationRecord(inviter, invitee));
        
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.market.service.MarketInvitationRecordService#updateStatus(co.fitstart.entity.market.MarketInvitationRecord, co.fitstart.entity.market.InvitationStatus)
     */
    public void updateStatus(MarketInvitationRecord marketInvitationRecord, InvitationStatus status) {
        genericDaoSupport.update(marketInvitationRecord.changeStatus(status));
    }

}
